﻿using System.IO;
using System.Reflection;


namespace TravWinControllerSpace
{
    /// <summary>
    /// Get application information that would typically be displayed in an About dialog.
    /// This information is retrieved from the containing assembly itself.
    /// </summary>
    public static class TravWinAbout
    {
        private static Assembly assembly
        { get { return Assembly.GetExecutingAssembly (); } }


        public static string Version
        {
            get
            {
                string result = assembly.GetName ().Version.ToString ();

                if (result.Length > 3 && result.EndsWith (".0"))
                    result = result.Substring (0, result.Length - 2);

                return result;
            }
        }


        public static string Title
        {
            get
            {
                object[] attributes = assembly.GetCustomAttributes (typeof (AssemblyTitleAttribute), false);
                if (attributes.Length > 0)
                {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute) attributes[0];
                    if (!string.IsNullOrEmpty (titleAttribute.Title))
                        return titleAttribute.Title;
                }

                // If the assembly has no title attribute, fall back to the file name.
                return Path.GetFileNameWithoutExtension (assembly.CodeBase);
            }
        }



        public static string Description
        {
            get
            {
                object[] attributes = assembly.GetCustomAttributes (typeof (AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0)
                    return "";

                return ((AssemblyDescriptionAttribute) attributes[0]).Description;
            }
        }


        public static string Product
        {
            get
            {
                object[] attributes = assembly.GetCustomAttributes (typeof (AssemblyProductAttribute), false);
                if (attributes.Length == 0)
                    return "";

                return ((AssemblyProductAttribute) attributes[0]).Product;
            }
        }


        public static string Copyright
        {
            get
            {
                object[] attributes = assembly.GetCustomAttributes (typeof (AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0)
                    return "";

                return ((AssemblyCopyrightAttribute) attributes[0]).Copyright;
            }
        }


        public static string Company
        {
            get
            {
                object[] attributes = assembly.GetCustomAttributes (typeof (AssemblyCompanyAttribute), false);
                if (attributes.Length == 0)
                    return "";

                return ((AssemblyCompanyAttribute) attributes[0]).Company;
            }
        }
    }
}
